package com.adcc.loadsheet.monitor.entity;

import com.adcc.loadsheet.monitor.util.AlarmEnum;

import java.util.HashSet;
import java.util.Set;

/**
 * 舱单监控mysql监控信息
 */
public class MysqlMonitor extends BaseEntity implements Cloneable{

    // 总体状态
    private MonitorStatus status = MonitorStatus.ABNORMAL;

    // 异常状态码(0：正常，1：异常)
    private String errorCode = "0";

    // 本模块异常的节点
    private Set<String> alarmContent = new HashSet<>();

    // 本模块正常的节点（用于判断告警确认后，部分节点正常后又异常需要重新告警）
    private Set<String> unAlarmContent = new HashSet<>();

    public MonitorStatus getStatus() {
        return status;
    }

    public void setStatus(MonitorStatus status) {
        this.status = status;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public Set<String> getAlarmContent() {
        return alarmContent;
    }

    public void setAlarmContent(Set<String> alarmContent) {
        this.alarmContent = alarmContent;
    }

    public Set<String> getUnAlarmContent() {
        return unAlarmContent;
    }

    public void setUnAlarmContent(Set<String> unAlarmContent) {
        this.unAlarmContent = unAlarmContent;
    }

    @Override
    public String toXML() throws Exception {
        return null;
    }

    @Override
    public String toJSON() throws Exception {
        return null;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        MysqlMonitor mysqlMonitor = new MysqlMonitor();
        mysqlMonitor.setStatus(status);
        mysqlMonitor.setErrorCode(errorCode);
        mysqlMonitor.setAlarmContent(alarmContent);
        mysqlMonitor.setUnAlarmContent(unAlarmContent);
        return mysqlMonitor;
    }

    /**
     * 异常状态码(0：正常，1：异常)
     */
    public void buildErrorCode() {
        StringBuilder sb = new StringBuilder();
        char[] states = new char[1];
        states[0] = status == MonitorStatus.NORMAL ? '0' : '1';
        for(char c : states){
            sb.append(c);
        }
        this.errorCode = sb.toString();

        // [2024-6-01：张丽娟：增加声音和弹窗告警的功能，系统支持对指定告警项进行声音和弹窗告警忽略的功能: 根据状态码获取正常节点和异常节点信息]
        // 本模块异常的节点
        Set<String> alarmContent = new HashSet<>();
        // 本模块正常的节点（用于判断告警确认后，部分节点正常后又异常需要重新告警）
        Set<String> unAlarmContent = new HashSet<>();

        AlarmEnum enumMysql = AlarmEnum.MONITOR_MYSQL;
        if (states[0] == '1') {
            alarmContent.add(enumMysql.getItem());
        }else{
            unAlarmContent.add(enumMysql.getItem());
        }

        this.alarmContent = alarmContent;
        this.unAlarmContent = unAlarmContent;
    }

}
